package com.workcell.workdata.xthings.constant;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 串口工作模式枚举
 */
@Getter
@AllArgsConstructor
public enum SerialWorkingModeEnum {
    NONE("0", "无"),
    TCP_UDP("1", "TCP/UDP透传"),
    HTTP("2", "HTTP传输"),
    ALI("3", "阿里云 MQTT"),
    ONENET("4", "ONENET MQTT"),
    BAIDU("5", "百度云 MQTT"),
    STANDARD("6", "标准 MQTT");

    private final String code;
    private final String msg;

    /**
     * 根据编码获取枚举
     *
     * @param code 编码
     * @return {@link SerialWorkingModeEnum}
     */
    public static SerialWorkingModeEnum getByCode(String code) {
        return Arrays.stream(SerialWorkingModeEnum.values())
                .filter(v -> StrUtil.equals(v.code, code))
                .findFirst()
                .orElse(null);
    }
}
